package org.linlinjava.litemall.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.IliquormallLibrary;
import org.linlinjava.litemall.db.service.ILiquormallLibraryService;
import org.linlinjava.litemall.wx.dto.LiquorLibraryCondition;
import org.linlinjava.litemall.wx.service.WxLiquorLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx/liquor/library")
@Validated
@Api(tags = "酒库类")
public class WxIliquormallLibraryController {
    private final Log logger = LogFactory.getLog(WxIliquormallLibraryController.class);

    @Autowired
    private WxLiquorLibraryService wxLiquorLibraryService;

    @Autowired
    private ILiquormallLibraryService liquorLibraryService;

    // TODO: 2022/5/22 library相应代码等mapper与service写完再打开
    @GetMapping("/detail")
    public Object detail(@RequestParam Integer id) {

        IliquormallLibrary liquorLibrary = liquorLibraryService.selectById(id);

        Map<String, Object> entity = new HashMap<>();
        entity.put("iLiquorLibrary", liquorLibrary);

        return ResponseUtil.ok(entity);
    }

    @GetMapping("/list")
    @ApiOperation("酒库列表返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "NAME", value = "酒名", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "province", value = "省份", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "香型", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "brand", value = "品牌", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "PAGE", value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = "LIMIT", value = "每页显示记录数", paramType = "query", required = true, dataType = "int")
    })
    public Object list(@RequestParam String name,
                       @RequestParam String province,
                       @RequestParam String type,
                       @RequestParam String brand,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit) {
        List<IliquormallLibrary> liquorLibraryList = liquorLibraryService.queryLiquorLibraryList(name, province, type, brand, page, limit);
        Map<String, Object> entity = new HashMap<>();
        entity.put("iLiquorLibraryList", liquorLibraryList);
        return ResponseUtil.ok(entity);
    }

    @GetMapping("/condition")
    public Object conditionList(@RequestParam String province,
                                @RequestParam String type,
                                @RequestParam String brand) {
        LiquorLibraryCondition liquorLibraryCondition = wxLiquorLibraryService.queryConditionsList(province, type, brand);
        Map<String, Object> entity = new HashMap<>();
        entity.put("liquorLibraryCondition", liquorLibraryCondition);
        return ResponseUtil.ok(entity);
    }

}
